Stata+Eviews+R:倍分法/双重差分操作教程
计量经济学服务中心专辑汇总!计量百科·资源·干货: Stata |Python |Matlab |Eviews |R Geoda |ArcGis |GeodaSpace |SPSS 一文读懂 |数据资源 |回归方法 |网络爬虫 门限回归 |工具变量 |内生性 |空间计量 因果推断 |合成控制法 |倾向匹配得分 |断点回归 |双重差分 面板数据 | 动态面板数据
倍差法一般用于检测在两个时期之间的政策变化某一关注变量产生的影响。顾名思义,该方法的使用依赖于对关注变量中两个差别,政策变化前后的时间差别和实验组与对照组之间的组间差别的计算。其基本思想是:首先分别计算实验组与对照组在政策变化前后的时间差别,然后将两个时间差别选行差分,得到的“差别中的差别”即可被认为是政策产生的“净影响”
双重差分法(Difference-in-difference,DID)有几种其他的称谓:倍差法、差分再差分等。该方法的原理非常简单,它要求数据期至少有两期,所有的样本被分为两类:实验组和控制组,其中实验组在第一期是没有受到政策影响,此后政策开始实施,第二期就是政策实施后的结果,控制组由于一直没有受政策干预,因此其第一期和第二期都是没有政策干预的结果。双重差分方法的测算也非常简单,两次差分的效应就是政策效应。
案例背景:在这个案例中,研究新泽西州最低工资的提高对快餐业就业水平的影响。比较了这一组餐馆员工人数的变化与相邻的宾夕法尼亚州的对照组。
1、调用数据
首先我们读入所需数据
2、生成交互项,命令为:
生成政策前后以及控制组虚拟变量,并将它们相乘产生交互项。
genr did =tr*t
3、进行双重差分操作
命令为:ls fte did tr t c
4、操作方法二:
结果解释:
交互项did的估计值为2.913982,p值为10%显著性水平上显著,即政策的确产生了显著影响。
下面进行扩展的DID模型分析。
交互项did的估计值为2.935020,p值为5%显著性水平上显著.
setwd("C:/Users/admin/Desktop")
library(readstata13)
cardkrueger1994<- read.dta13("cardkrueger1994.dta")
cardkrueger$treat <- ifelse(cardkrueger$treated=="NJ",cardkrueger$treat <- 1,cardkrueger$treat <- 0)
df=fte~treat+t+I(treat*t)
ols <- lm(df,data=cardkrueger)
summary(ols)
结果为:
命令为:
diff outcome_var [if] [in] [weight] ,[ options]
模型必选项介绍:
outcome_var :结果变量
period(varname) :实验期变量
treated(varname) :处理变量
cov(varlist) :协变量。
可选项介绍:
cov(varlist),协变量,加上kernel可以估计倾向得分
kernel, 执行双重差分倾向得分匹配
id(varname),kernel选项要求使用
bw(#) ,核函数的带宽,默认是0.06
ktype(kernel),核函数的类型.
rcs Indicates that the kernel is set for repeated cross section. This option does not require option id(varname). Option rcs strongly assumes that covariates in cov(varlist) do not vary over time.
qdid(quantile),执行分位数双重差分
pscore(varname) .提供倾向得分
logit,进行倾向得分计算,默认probit回归
ddd(varname),三重差分
数据结构如下:
1、DID with no covariates不带协变量的估计
diff fte, t(treated) p(t)
bootstrapped 稳健标准误
2、DID with covariates带协变量的估计
diff fte, t(treated) p(t) cov(bk kfc roys)
diff fte, t(treated) p(t) cov(bk kfc roys) report
diff fte, t(treated) p(t) cov(bk kfc roys) report bs
3、Kernel Propensity Score Diff-in-Diff
diff fte, t(treated) p(t) cov(bk kfc roys) kernel rcs
diff fte, t(treated) p(t) cov(bk kfc roys) kernel rcs support
diff fte, t(treated) p(t) cov(bk kfc roys) kernel rcs support addcov(wendys)
diff fte, t(treated) p(t) kernel rcs ktype(gaussian) pscore(_ps)
diff fte, t(treated) p(t) cov(bk kfc roys) kernel rcs support addcov(wendys) bs reps(50)
4、 Quantile Diff-in-Diff 分位数双重差分法
diff fte, t(treated) p(t) qdid(0.25)
diff fte, t(treated) p(t) qdid(0.50)
diff fte, t(treated) p(t) qdid(0.75)
diff fte, t(treated) p(t) qdid(0.50) cov(bk kfc roys)
diff fte, t(treated) p(t) qdid(0.50) cov(bk kfc roys) kernel id(id) diff fte, t(treated) p(t) qdid(0.50) cov(bk kfc roys) kernel rcs
5、Balancing test of covariates.包含协变量的控制组与实验组之间差异检验
diff fte, t(treated) p(t) cov(bk kfc roys wendys) test
diff fte, t(treated) p(t) cov(bk kfc roys wendys) test id(id) kernel
diff fte, t(treated) p(t) cov(bk kfc roys wendys) test kernel rcs
6. Triple differences (consider bk is a second treatment category).
三重差分法
diff fte, t(treated) p(t) ddd(bk)